package cn.edu.cdu.farmdeal.config;

import cn.edu.cdu.farmdeal.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: tupeng
 * @Date: 2020/3/12
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/static/**").addResourceLocations("classpsth:/static/"
////                "/css/**",
////                "/font/**",
////                "/img/**",
////                "/js/**",
////                "/plugins/**"
//        );
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //SpringMVC下，拦截器的注册需要排除对静态资源的拦截(*.css,*.js)
        //SpringBoot已经做好了静态资源的映射，因此我们无需任何操作
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/static/login.html")
                .excludePathPatterns("/login")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/checkUser")
                .excludePathPatterns("index.html")
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/oauth/qq/callback");
//                        "/index.html",
//                        "/detail.html",
//                        "/templates/**",
//                        "/swiper/**",
//                        "/farm_deal/**",
//
//                        "/css/**",
//                        "/font/**",
//                        "/img/**",
//                        "/js/**",
//                        "/plugins/**",
//                        "/user/**",
//                        "/**/.html"
//                        );
    }
}
